#include <iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#define inf 0x3f3f3f3f

using namespace std;

int N;
int map[1010][1010];
int MIN(int a,int b)
{
    return a<b?a:b;
}
void floyd()
{
    for(int k=1;k<=N;++k)
    {
        for(int i=1;i<=N;++i)
        {
            for(int j=1;j<=N;++j)
            {
                map[i][j]=MIN(map[i][j],map[i][k]+map[k][j]);
            }
        }
    }
}
int main()
{
    int i,j,k;
    while(scanf("%d",&N),N)
    {
        int a,b,m;
        memset(map,0x3f,sizeof(map));
        for(i=1;i<=N;++i)
        {
            scanf("%d",&m);
            for(j=0;j<m;++j)
            {
                scanf("%d%d",&a,&b);
                if(map[i][a]>b)map[i][a]=b;
            }
        }
        floyd();
        int ans=inf,pep,temp,flag=1;
        for(i=1;i<=N;++i)
        {
            temp=0;
            for(j=1;j<=N;++j)
            {
                if(i==j)continue;
                if(map[i][j]>temp)temp=map[i][j];
            }
            if(ans>temp)
            {
                ans=temp;pep=i;
            }
        }
        if(ans==inf)
            printf("disjoint\n");
        else
            printf("%d %d\n",pep,ans);
    }
    return 0;
}
